package com.iot.iotplus.exception;



import com.iot.iotplus.base.Result;
import com.iot.iotplus.utils.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

//全局异常处理
@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(value= SQLException.class)
    public Result<Object> handleSQLException(SQLException e){
        String message = e.getMessage();
        return ResultUtil.failed(message);
    }

    @ResponseBody
    @ExceptionHandler(value= NullPointerException.class)
    public Result<Object> handleNullPointerException(NullPointerException e){
        String message = e.getMessage();
        return ResultUtil.failed(message);
    }
    @ResponseBody
    @ExceptionHandler
    public Result<Object> arithmeticExceptionHandler(ArithmeticException e){
        String message = e.getMessage();
        return ResultUtil.failed(message);
    }
    @ResponseBody
    @ExceptionHandler(value= NetworkDiskException.class)
    public Result<Object> handleException(NetworkDiskException e){
        String message = e.getMessage();
        return ResultUtil.failed(message);
    }



}
